package collection;

import java.util.concurrent.CopyOnWriteArrayList;
import java.util.concurrent.CopyOnWriteArraySet;
import java.util.concurrent.locks.ReentrantReadWriteLock;


public class CopyOnWriteArrayList1 extends CopyOnWriteArrayList {


    static ReentrantReadWriteLock.WriteLock writeLock = new ReentrantReadWriteLock().writeLock();
    static ReentrantReadWriteLock.ReadLock readLock = new ReentrantReadWriteLock().readLock();

    @Override
    public boolean add(Object o) {
        writeLock.lock();
        boolean s = super.add(o);
        writeLock.unlock();
        return s;
    }

    @Override
    public Object get(int index) {
        readLock.lock();
        Object o = super.get(index);
        readLock.unlock();
        return o;
    }
}
